#ifndef HOTKEYTABLEMODEL_H
#define HOTKEYTABLEMODEL_H

#include <QAbstractTableModel>

/**
 * @brief The HotKeyTableModel class
 * 抽象模型，进行子类化以创建表模型
 */
class HotKeyTableModel : public QAbstractTableModel
{
    Q_OBJECT

public:
    explicit HotKeyTableModel(QObject *parent = nullptr);

    // Header:
    QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;

    // Basic functionality:
    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    int columnCount(const QModelIndex &parent = QModelIndex()) const override;

    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;

     // 可编辑的模型需要实现 setData（），并实现 flags（） 以返回包含 Qt::ItemIsEditable 的值。
    bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole)  override;
   Qt::ItemFlags flags(const QModelIndex &index) const override;

    //设置表头数据
    void setTableHeaderData(const QStringList& list)  {
         m_headData = list;
    }
    //设置表格数据
    void setSourceData(const QMap<int, QVector<QString>>& map) {
        //刷新表格
        beginResetModel();
        m_datas = map;
        endResetModel();
    }

public:

signals:
    void sig_dataChanged ( int row, const int column, const QString& key);

private:
    int dataHandle(const QString & sKeyText);


private:
    QStringList m_headData; //表头数据
    QMap<int, QVector<QString>> m_datas;    //显示的数据
};

#endif // HOTKEYTABLEMODEL_H
